package _01_event_bus._1_0_0_classification

import akka.actor.ActorRef
import akka.event.{EventBus, LookupClassification}

/**
  * @author galudisu
  */

final case class MsgEnvelope(topic: String, payload: Any)

class LookupBusImpl extends EventBus with LookupClassification {

  override type Event = MsgEnvelope
  override type Classifier = String
  override type Subscriber = ActorRef

  // 数据结构的索引大小
  override protected def mapSize(): Int = 128
  // 订阅者顺序
  override protected def compareSubscribers(a: ActorRef, b: ActorRef): Int = a.compareTo(b)
  // 从接收的事件，提取分类器
  override protected def classify(event: MsgEnvelope): String = event.topic
  // 发布
  override protected def publish(event: MsgEnvelope, subscriber: ActorRef): Unit = subscriber ! event.payload
}

